// @ts-nocheck - TODO: Fix TypeScript issues
import { getNewSiteParams } from 'calypso/lib/signup/step-actions';

describe( 'get-new-site-params', () => {
	test( 'should set the correct payload when flowToCheck is provided', () => {
		const { options } = getNewSiteParams( {
			dependencies: {},
			flowToCheck: 'myFlow',
		} );

		expect( options ).toHaveProperty( 'site_creation_flow', 'myFlow' );
		expect( options ).toHaveProperty( 'use_theme_annotation', false );
		expect( options ).toHaveProperty( 'default_annotation_as_primary_fallback', true );
		expect( options ).toHaveProperty( 'designType', undefined );
		expect( options ).toHaveProperty( 'wpcom_public_coming_soon', 1 );

		expect( options ).not.toHaveProperty( 'site_segment' );
	} );

	describe( 'For preselected url', () => {
		test( 'and a free domain it should generate the correct payload', () => {
			const result = getNewSiteParams( {
				dependencies: {},
				siteUrl: 'testing_free_domain',
			} );

			expect( result ).toHaveProperty( 'blog_name', 'testing_free_domain' );
			expect( result ).toHaveProperty( 'find_available_url', false );
		} );

		test( 'and a paid domain it should generate the correct payload', () => {
			const result = getNewSiteParams( {
				dependencies: {},
				isPurchasingDomainItem: true,
				siteUrl: 'test.com',
			} );

			expect( result ).toHaveProperty( 'blog_name', 'test.com' );
			expect( result ).toHaveProperty( 'find_available_url', true );
		} );
	} );

	describe( 'For no selected url', () => {
		test( 'and forceAutoGeneratedBlogName dependency it should set the correct payload using current user username', () => {
			const result = getNewSiteParams( {
				dependencies: {},
				state: {
					signup: {
						dependencyStore: {
							forceAutoGeneratedBlogName: true,
						},
					},
					currentUser: {
						user: { username: 'myUser' },
					},
				},
			} );

			expect( result ).toHaveProperty( 'blog_name', 'myUser' );
			expect( result ).toHaveProperty( 'find_available_url', true );
		} );

		test( 'and forceAutoGeneratedBlogName dependency it should set the correct payload using the username dependency', () => {
			const result = getNewSiteParams( {
				dependencies: {},
				state: {
					signup: {
						dependencyStore: {
							forceAutoGeneratedBlogName: true,
							username: 'myUser',
						},
					},
				},
			} );

			expect( result ).toHaveProperty( 'blog_name', 'myUser' );
			expect( result ).toHaveProperty( 'find_available_url', true );
		} );
	} );
} );
